package com.wpzf.ndhc.controller;

import com.wpzf.common.core.web.domain.AjaxResult;
import com.wpzf.ndhc.service.WpzfNdhcGTYDockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wpzfNdhcGTY")
public class WpzfNdhcGTYDockController {

    @Autowired
    private WpzfNdhcGTYDockService wpzfNdhcGTYDockServiceImpl;

    //获取用户信息 直接登陆拿到token
    @CrossOrigin(origins = "*", maxAge = 3600) // 允许所有源，并设置缓存时间为3600秒
    @RequestMapping(value = "/getUserInfo", method = RequestMethod.POST)
    public AjaxResult getUserInfo(@RequestBody Map<String, Object> param) {
        String user_name = wpzfNdhcGTYDockServiceImpl.getUserInfo(param);
        return AjaxResult.success("获取用户信息", user_name);
    }

    //省级地块审核 保存结果
    @CrossOrigin(origins = "*", maxAge = 3600) // 允许所有源，并设置缓存时间为3600秒
    @RequestMapping(value = "/saveResult", method = RequestMethod.POST)
    public AjaxResult saveResult(@RequestBody Map<String, Object> param) {
        try {
            Integer rest = wpzfNdhcGTYDockServiceImpl.saveResult(param);
            if (rest > 0) {
                wpzfNdhcGTYDockServiceImpl.updateHcjgsm(param);
                return AjaxResult.success("保存结果成功", rest);
            } else {
                return AjaxResult.error("保存结果失败");
            }
        } catch (Exception e) {
            return AjaxResult.error("保存结果失败");
        }
    }

    //省级地块审核 回显保存结果
    @CrossOrigin(origins = "*", maxAge = 3600) // 允许所有源，并设置缓存时间为3600秒
    @RequestMapping(value = "/queryResult", method = RequestMethod.POST)
    public AjaxResult queryResult(@RequestBody Map<String, Object> param) {
        try {
            Map<String, Object> rest = wpzfNdhcGTYDockServiceImpl.queryResult(param);
            return AjaxResult.success("回显保存结果", rest);
        } catch (Exception e) {
            return AjaxResult.error("保存结果失败");
        }
    }

    //省级地块审核 基本信息
    @CrossOrigin(origins = "*", maxAge = 3600) // 允许所有源，并设置缓存时间为3600秒
    @RequestMapping(value = "queryDetails", method = RequestMethod.POST)
    public AjaxResult queryDetails(@RequestBody Map<String, Object> param) {
        try {
            Map<String, Object> rest = wpzfNdhcGTYDockServiceImpl.queryDetails(param);
            return AjaxResult.success("基本信息", rest);
        } catch (Exception e) {
            return AjaxResult.error("基本信息");
        }
    }

    //按照区县统计核查情况接口
    @CrossOrigin(origins = "*", maxAge = 3600) // 允许所有源，并设置缓存时间为3600秒
    @RequestMapping(value = "getVerificationStatsByDistrict", method = RequestMethod.POST)
    public AjaxResult getVerificationStatsByDistrict(@RequestBody Map<String, Object> param) {
        try {
            List<Map<String, Object>> rest = wpzfNdhcGTYDockServiceImpl.getVerificationStatsByDistrict(param);
            return AjaxResult.success("按照区县统计核查情况", rest);
        } catch (Exception e) {
            return AjaxResult.error("按照区县统计核查情况");
        }
    }

    //按照地块统计核查结果说明信息展示接口
    @CrossOrigin(origins = "*", maxAge = 3600) // 允许所有源，并设置缓存时间为3600秒
    @RequestMapping(value = "getVerificationResultInfoByDK", method = RequestMethod.POST)
    public AjaxResult getVerificationResultInfoByDK(@RequestBody Map<String, Object> param) {
        try {
            List<Map<String, Object>> rest = wpzfNdhcGTYDockServiceImpl.getVerificationResultInfoByDK(param);
            return AjaxResult.success("按照地块统计核查结果说明信息展示", rest);
        } catch (Exception e) {
            return AjaxResult.error("按照地块统计核查结果说明信息展示");
        }
    }

}
